package com.alks.function.mapper.pack;

import com.alks.common.data.dto.SysUserTokenDTO;
import com.alks.entity.data.entity.*;
import com.alks.function.data.request.PcSoleInStockReq;
import com.alks.function.data.request.order.PcOrderDataRsjRequest;
import com.alks.function.data.request.pack.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.Mapper;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface PackMaterialMapping {
    List<PackMaterialStorageRep> listPackMaterialStorage(PcPackMaterialRequest request);

    Long getPackInStorageTotal(PcPackMaterialRequest request);

    Long getPackInStorageQtyTotal(PcPackMaterialRequest request);

    @Select("SELECT SLIP_REASON FROM PC_SLIP_DETAIL_PACK WHERE SLIP_REASON IS NOT NULL AND SLIP_TYPE = 'I' GROUP BY SLIP_REASON")
    List<String> getPackSlipReasonInStorage();

    @Select("SELECT DEPT_NO,DEPT_NAME FROM PC_SLIP_DETAIL_PACK WHERE DEPT_NO IS NOT NULL AND DEPT_NAME IS NOT NULL  AND SLIP_TYPE = 'I' GROUP BY DEPT_NO,DEPT_NAME ")
    List<Map<String, String>> getPackDeptInStorage();

    @Select("SELECT VENDOR_NO,VENDOR_NAME FROM PC_SLIP_DETAIL_PACK WHERE VENDOR_NO IS NOT NULL AND VENDOR_NAME IS NOT NULL  AND SLIP_TYPE = 'I' GROUP BY VENDOR_NO,VENDOR_NAME")
    List<Map<String, String>> getPackVenDorInStorage();

    @Select("SELECT TYPE_NAME FROM PC_SLIP_DETAIL_PACK WHERE TYPE_NAME IS NOT NULL AND SLIP_TYPE = 'I' GROUP BY TYPE_NAME")
    List<String> getPackTypeInStorage();

    @Select("SELECT DEPT_NO,DEPT_NAME FROM PC_SLIP_DETAIL_PACK WHERE DEPT_NO IS NOT NULL AND DEPT_NAME IS NOT NULL  AND SLIP_TYPE = 'O' GROUP BY DEPT_NO,DEPT_NAME ")
    List<Map<String, String>> getPcPackMaterialOutDept();

    @Select("SELECT SLIP_REASON FROM PC_SLIP_DETAIL_PACK WHERE SLIP_REASON IS NOT NULL AND SLIP_TYPE = 'O' GROUP BY SLIP_REASON")
    List<String> getPcPackMaterialOutSlipReason();

    List<PcPackMaterialOutRep> getPackMaterialOut(PcPackMaterialOutRequest request);

    @Select("SELECT s.MTL_NO,s.MTL_NAME,p.MTL_COLOR FROM SD_MATERIAL s\n" +
            "LEFT JOIN (SELECT MTL_NO,MTL_COLOR,MTL_NAME FROM PC_SLIP_DETAIL_PACK GROUP BY  MTL_NO,MTL_COLOR,MTL_NAME) p\n" +
            "ON p.MTL_NO = s.MTL_NO AND p.MTL_NAME = s.MTL_NAME")
    List<PcPackMaterialStockCondition> getPcPackStockCondition();

    List<PcPackStockRep> getPcPackStock(PcPackStockRequest request);

    Long getPcPackStockTotals(PcPackStockRequest request);

    @Select("SELECT LOT_NO,VENDOR_NAME VENDOR,SLIP_DATE,SLIP_NO,SLIP_REASON,QTY FROM PC_SLIP_DETAIL_PACK WHERE MTL_NO = #{mtlNo} AND MTL_NAME = #{mtlName} AND SLIP_TYPE = 'I' ")
    List<PcPackInDetailRep> getPcPackStockIn(@Param("mtlNo") String mtlNo, @Param("mtlName") String mtlName);

    @Select("SELECT LOT_NO,DEPT_NAME,SLIP_DATE,SLIP_NO,SLIP_REASON,QTY FROM PC_SLIP_DETAIL_PACK WHERE MTL_NO = #{mtlNo} AND MTL_NAME = #{mtlName} AND SLIP_TYPE = 'O' ")
    List<PcPackOutDetailRep> getPcPackStockOut(@Param("mtlNo") String mtlNo, @Param("mtlName") String mtlName);

    @Select("SELECT SUM(QTY) FROM PC_SLIP_DETAIL_PACK WHERE MTL_NO = #{mtlNo} AND MTL_NAME = #{mtlName} AND SLIP_TYPE = 'I' ")
    Long getPcPackStockInTotal(@Param("mtlNo") String mtlNo, @Param("mtlName") String mtlName);

    @Select("SELECT SUM(QTY) FROM PC_SLIP_DETAIL_PACK WHERE MTL_NO = #{mtlNo} AND MTL_NAME = #{mtlName} AND SLIP_TYPE = 'O' ")
    Long getPcPackStockOutTotal(@Param("mtlNo") String mtlNo, @Param("mtlName") String mtlName);

    Integer getPackMaterialOutTotal(PcPackMaterialOutRequest request);

    BigDecimal getPackMaterialOutQtySum(PcPackMaterialOutRequest request);

    @Select("SELECT TYPE_NAME,TYPE_NO,LEVEL_CODE FROM SD_MTL_TYPE_NEW WHERE PARENT_LEVEL IS NULL")
    List<PcPackFaceMtlConditionRep> getPcPackFaceCondition1();

    @Select("SELECT TYPE_NAME,TYPE_NO,LEVEL_CODE FROM SD_MTL_TYPE_NEW WHERE PARENT_LEVEL = #{mtlNo}")
    List<PcPackFaceMtlConditionRep> getPcPackFaceCondition2(String mtlNo);

    List<PcPackFaceMtlRep> getPcPackFaceMtl(PcPackFaceMtlRequest request);

    List<PcPackFaceMtlDetailRep> getPcPackFaceMtlDeTail(@Param("request") PcPackFaceMtlDetailRequest request);

    List<PcDesignGetRep> collectAllList(PcOrderDataRsjRequest request);

    BigDecimal collectAllOrderQty(PcOrderDataRsjRequest request);

    BigDecimal collectAllProdQty(PcOrderDataRsjRequest request);

    Integer deleteFromProdStatus(@Param("rep") List<PcDesignGetRep> rep, @Param("choose") String choose);

    List<PcCutStitchRep> collectCutD1(PcOrderDataRsjRequest request);

    void deleteByCutAStitch(@Param("rep") PcCutStitchRep rep, @Param("choose") String choose);

    List<String> getLotNoByProdStep(@Param("req") ScanCollectionAllReq req, @Param("choose") String choose);

    void insertIntoProdStep(@Param("req") ScanCollectionAllReq req, @Param("prodStep") String prodStep, @Param("choose") String choose, @Param("user") SysUserTokenDTO user);

    List<String> getCutStep(@Param("req") ScanCollectionAllReq req, @Param("choose") String choose);

    void insertIntoStatusOther(TestBoardsScan req);

    String getLotNoByStitchBarcode(@Param("req") ScanCollectionAllReq req, @Param("choose") String choose);

    List<PcSoleInPcProdRep> getSolePurPreMtlOther(PcSoleInStockReq req);

    Integer getCountByPurNo(PcSoleInStockReq req);

    void insertIntoOrderProd(@Param("list") List<PcSoleInPcProdRep> list, @Param("name") String name, @Param("loginName") String loginName);

    @Select("select count(*) from PC_ORDER_HEAD where order_id = #{lotNo}")
    Integer getCountByLotNo(String lotNo);

    List<String> getDipathchNoByProdStep(@Param("req") ScanCollectionAllReq req, @Param("choose") String choose);

    void deleteByPcLotHead(@Param("lotNo") String lotNo, @Param("scheduleNo") String scheduleNo);

    String getScheduleNo();

    BigDecimal getProdQtyByNo(@Param("req") ScanCollectionAllReq req, @Param("choose") String choose);

    BigDecimal getCurrentOrderQty(ScanCollectionAllReq req);

    void updatePcOrderStatus(PcDesignGetRep rep);

    Map<String,Object> getDipathchNoByProdStepType(@Param("req") ScanCollectionAllReq req, @Param("choose") String choose);

    BigDecimal getProdQtyByStitchNo(@Param("req") ScanCollectionAllReq req, @Param("choose") String choose);
}
